1 00:00:00,630 --> 00:00:06,360 Let's work on the kills and deaths part of our leaderboard, something every first person shooter game 2 00:00:06,360 --> 00:00:06,960 needs. 3 00:00:06,960 --> 00:00:09,630 And I got the test server running with two players. 4 00:00:09,630 --> 00:00:10,680 There's my other player. 5 00:00:10,680 --> 00:00:11,640 I'm going to kill them. 6 00:00:14,970 --> 00:00:18,060 Bam, We got a kit one for kills the other guy. 7 00:00:18,060 --> 00:00:22,680 I got one for deaths and I awarded the player 50 points for the kill. 8 00:00:22,710 --> 00:00:24,290 I thought that would be pretty useful. 9 00:00:24,300 --> 00:00:26,160 Let's go ahead and get started. 10 00:00:26,790 --> 00:00:29,870 We are going to use the creator tag pattern. 11 00:00:29,880 --> 00:00:32,580 It's a popular roadblock programming technique. 12 00:00:32,580 --> 00:00:39,510 Basically, when we damage a character, we place a tag on the humanoid with the attackers info so that 13 00:00:39,510 --> 00:00:46,820 if the character dies soon after you hurt them, the last person to do damage gets credit for the kill. 14 00:00:46,830 --> 00:00:51,030 You can find a lot of the same code in the roadblocks weapons. 15 00:00:51,030 --> 00:00:53,220 Let's go to our pistol. 16 00:00:53,220 --> 00:01:00,470 I have it in the starter pack simple pistol and then open up the damage script. 17 00:01:00,480 --> 00:01:01,590 There we go. 18 00:01:03,420 --> 00:01:03,570 All right. 19 00:01:03,570 --> 00:01:06,600 Let's get down to lines and start defining our functions. 20 00:01:07,050 --> 00:01:11,580 Do a local function tag humanoid. 21 00:01:11,610 --> 00:01:16,260 I'm going to pass in the humanoid of the thing getting hurt and the player doing the hurting. 22 00:01:16,830 --> 00:01:19,440 And then I'm going to make a variable for my creator. 23 00:01:19,440 --> 00:01:20,160 Tag. 24 00:01:20,880 --> 00:01:23,250 Create a tag equals instance. 25 00:01:23,250 --> 00:01:27,670 New object value him. 26 00:01:27,960 --> 00:01:31,080 So the parent is the humanoid that's getting hurt. 27 00:01:32,190 --> 00:01:37,320 Let's go ahead and get our creator tag name and set that to creator. 28 00:01:37,410 --> 00:01:42,960 You should keep this consistent because a lot of roadblocks, weapons already have this implemented 29 00:01:42,960 --> 00:01:44,640 and they're calling it creator. 30 00:01:44,640 --> 00:01:50,640 So you'll be able to use other roadblocks, weapons that have this seamlessly without doing anything 31 00:01:50,640 --> 00:01:51,180 new. 32 00:01:51,450 --> 00:01:58,560 Let's get our creator tag value and have that equal to the player that did the damage. 33 00:01:58,710 --> 00:01:59,090 Right. 34 00:01:59,100 --> 00:02:05,190 And we have that right because we have that right here on shoot that came through with our remote event. 35 00:02:06,590 --> 00:02:07,520 What else do we need? 36 00:02:07,550 --> 00:02:08,720 Let's do the game. 37 00:02:08,720 --> 00:02:10,950 Dot debris service. 38 00:02:10,970 --> 00:02:15,800 Add item creator tag and make it disappear in 2 seconds. 39 00:02:15,800 --> 00:02:19,680 So we have to do something with this in 2 seconds after we tag the person. 40 00:02:19,700 --> 00:02:22,550 They can't just walk around with a tag for like 45 minutes. 41 00:02:22,550 --> 00:02:26,780 Then when they die because they jumped off of something, you get credit. 42 00:02:27,290 --> 00:02:27,590 All right. 43 00:02:27,590 --> 00:02:29,000 Now we're going to do another function. 44 00:02:29,000 --> 00:02:33,760 This is going to be called un tag humanoid. 45 00:02:34,820 --> 00:02:36,030 I'll pass in the humanoid. 46 00:02:36,050 --> 00:02:37,290 I'll just say HUME. 47 00:02:37,310 --> 00:02:38,370 Easier to type. 48 00:02:38,390 --> 00:02:43,640 Now I'm going to do a for loop for I and V in pairs. 49 00:02:44,090 --> 00:02:48,590 HUME Get children. 50 00:02:51,180 --> 00:02:51,900 Do. 51 00:02:51,930 --> 00:02:55,200 We're going to remove all the creator tags. 52 00:02:55,500 --> 00:03:01,350 Every time somebody hits somebody, we're going to take other people's creator tags off so they don't 53 00:03:01,350 --> 00:03:04,690 get credit to just the person who did the kill. 54 00:03:04,710 --> 00:03:15,030 So V is a tag, maybe a tag if there's one on the humanoid when I check though, if a V is a object 55 00:03:15,030 --> 00:03:16,050 of value 56 00:03:19,110 --> 00:03:31,470 and V dot name equals equals o lowercase creator, then v destroy, right? 57 00:03:31,470 --> 00:03:34,980 So get rid of anybody else's so that they don't get credit. 58 00:03:34,980 --> 00:03:38,040 Only you get credit for the kill the last person to touch them. 59 00:03:38,130 --> 00:03:39,600 Then what we're going to do here? 60 00:03:39,630 --> 00:03:42,480 Get this UN tag humanoid. 61 00:03:42,570 --> 00:03:43,590 Copy it. 62 00:03:43,590 --> 00:03:46,440 Right before we do the take damage. 63 00:03:47,630 --> 00:03:47,890 Right. 64 00:03:48,060 --> 00:03:58,440 Check to see if the humanoid exists and tag the humanoid and then tag the humanoid with your tag un. 65 00:03:58,440 --> 00:04:00,000 Tag everybody else's stuff. 66 00:04:00,390 --> 00:04:01,950 Tag your stuff. 67 00:04:03,610 --> 00:04:04,810 Now what? 68 00:04:04,840 --> 00:04:10,480 Well, now what we have to do is get the players died event and start doing stuff with that tagging 69 00:04:10,480 --> 00:04:13,310 system so we can get points and things like that. 70 00:04:13,330 --> 00:04:17,530 Let's go to server script service, open up the game manager. 71 00:04:17,530 --> 00:04:24,190 When a player is added to the game, we add this board that's good in all, but we need to do more than 72 00:04:24,190 --> 00:04:24,670 that. 73 00:04:24,670 --> 00:04:28,720 So I'm going to add this anonymous function, right? 74 00:04:28,720 --> 00:04:29,950 There's no name on it. 75 00:04:29,950 --> 00:04:33,310 It's just called when Player added is fired. 76 00:04:33,550 --> 00:04:39,670 I'm going to add the board pass in the player this time because it's not an automatic connection. 77 00:04:39,970 --> 00:04:45,220 Then I'm going to get the player character added event. 78 00:04:45,280 --> 00:04:49,510 Connect that to another anonymous function. 79 00:04:49,510 --> 00:04:51,430 Character is going to get passed in. 80 00:04:51,430 --> 00:04:58,630 So player added fires when you enter the game, character added fires when your character is added to 81 00:04:58,630 --> 00:04:59,020 the game. 82 00:04:59,020 --> 00:05:05,530 So if you die and you respawn character added is going to fire every single time you're responding, 83 00:05:05,530 --> 00:05:07,990 this only fires when you enter the game. 84 00:05:08,890 --> 00:05:11,290 So what are we going to do? 85 00:05:11,290 --> 00:05:15,160 Let's get our humanoid from the character because now we've got a character, right? 86 00:05:15,160 --> 00:05:16,330 It's Char. 87 00:05:16,600 --> 00:05:21,580 We'll do a wait for child just in case there's a little slow starting up and then we're going to get 88 00:05:21,580 --> 00:05:22,630 our humanoid. 89 00:05:23,290 --> 00:05:27,460 Now, with the humanoid, we can capture the diet event. 90 00:05:27,460 --> 00:05:31,450 We're going to say HUME Dot died. 91 00:05:32,140 --> 00:05:36,400 We're going to connect that to another anonymous function. 92 00:05:36,400 --> 00:05:42,130 Nothing gets passed in there and we'll get, oh, you know what we should do. 93 00:05:42,130 --> 00:05:48,610 I don't know if you noticed this, but you can actually shoot your gun after you die until you respond 94 00:05:48,640 --> 00:05:50,860 as a roadblocks glitch, in my opinion. 95 00:05:50,860 --> 00:05:52,300 But we're going to fix that. 96 00:05:52,300 --> 00:05:53,260 We're going to say. 97 00:05:53,260 --> 00:06:03,760 HUME on equip tools, just in case you're holding anything for that two or 3 seconds until they respond 98 00:06:04,450 --> 00:06:06,580 that way, you can't fire after you're dead. 99 00:06:07,030 --> 00:06:08,950 So we got that taken care of. 100 00:06:08,950 --> 00:06:09,790 What else are we going to do? 101 00:06:09,970 --> 00:06:12,070 We've got to get our tag from the humanoid. 102 00:06:12,280 --> 00:06:12,640 Right. 103 00:06:12,640 --> 00:06:14,290 The whole reason we're here. 104 00:06:14,620 --> 00:06:15,220 Fine. 105 00:06:15,220 --> 00:06:16,600 First child. 106 00:06:17,950 --> 00:06:19,270 Whoops, I always do that. 107 00:06:19,270 --> 00:06:21,850 Lowercase Creator. 108 00:06:21,850 --> 00:06:24,460 So we're going to look for the creator tag on the humanoid. 109 00:06:24,460 --> 00:06:29,950 There should only be one if tag and tag dot value. 110 00:06:29,950 --> 00:06:35,590 So we want to make sure that the tag exists and the tag has the value just in case something weird happened 111 00:06:35,590 --> 00:06:39,160 and we didn't assign the value, say local. 112 00:06:39,160 --> 00:06:42,370 I'm going to call this e player for enemy player. 113 00:06:42,370 --> 00:06:44,020 This is going to be the enemy player's name. 114 00:06:44,020 --> 00:06:45,940 That's the tag value. 115 00:06:45,940 --> 00:06:47,260 So we died. 116 00:06:47,260 --> 00:06:48,820 Someone else shot us. 117 00:06:48,820 --> 00:06:51,400 That is going to be the one who shot us. 118 00:06:51,400 --> 00:06:52,960 We're going to give them credit. 119 00:06:52,960 --> 00:07:03,790 We're going to say e player leader stats dot kills, make sure kills is on your leader stats value plus 120 00:07:03,790 --> 00:07:04,540 equals one. 121 00:07:04,540 --> 00:07:12,340 Take the old value out of one and then let's give them some points to E Player leader stats. 122 00:07:12,340 --> 00:07:13,240 I spell that right. 123 00:07:13,240 --> 00:07:16,630 Leader Stats points. 124 00:07:17,200 --> 00:07:18,340 How many points do we give them? 125 00:07:18,340 --> 00:07:19,570 Let's give them 50. 126 00:07:19,870 --> 00:07:21,100 50 points. 127 00:07:21,100 --> 00:07:23,500 Now, how do you keep track of deaths? 128 00:07:23,500 --> 00:07:26,590 Well, we don't need to be tagged for the death. 129 00:07:26,590 --> 00:07:27,910 We just need to count it. 130 00:07:27,910 --> 00:07:34,270 So underneath this if statement for tagging player. 131 00:07:34,270 --> 00:07:37,780 So not the enemy player but the player who died. 132 00:07:38,410 --> 00:07:40,270 We'll say leader stats. 133 00:07:42,330 --> 00:07:45,040 Dot deaths. 134 00:07:45,900 --> 00:07:49,200 Value plus equals one. 135 00:07:49,200 --> 00:07:49,530 Right. 136 00:07:49,650 --> 00:07:51,960 Make sure these are spelled the same as that. 137 00:07:51,960 --> 00:07:52,920 It's on your leaderboard. 138 00:07:52,920 --> 00:07:55,920 The name of of the metric on your leaderboard. 139 00:07:55,920 --> 00:07:58,290 And we should be good to go. 140 00:07:59,250 --> 00:07:59,490 All right. 141 00:07:59,490 --> 00:08:02,950 We need to test this out and the test server because we need more than one player. 142 00:08:02,970 --> 00:08:05,610 Let's go to where is it view test. 143 00:08:05,610 --> 00:08:06,270 There it is. 144 00:08:06,600 --> 00:08:08,130 And two players. 145 00:08:08,130 --> 00:08:08,970 That's good. 146 00:08:08,970 --> 00:08:10,410 I'm going to hit the start button. 147 00:08:10,410 --> 00:08:11,820 Then I'm going to pause the video. 148 00:08:11,820 --> 00:08:14,160 All this starts up because it takes a long time. 149 00:08:16,380 --> 00:08:16,920 All right. 150 00:08:16,920 --> 00:08:18,450 Our game is starting up. 151 00:08:19,470 --> 00:08:20,820 I'm going to get my pistol. 152 00:08:22,530 --> 00:08:23,520 There's my other guy. 153 00:08:24,680 --> 00:08:27,370 Oh, he's got his invulnerability bubble on. 154 00:08:27,380 --> 00:08:28,430 Hold on. 155 00:08:33,340 --> 00:08:34,390 Cool. 156 00:08:34,630 --> 00:08:39,730 And if you'll notice, if I die, I'm going to go here. 157 00:08:39,730 --> 00:08:45,640 I'm going to reset my character, and now I'm clicking, but I'm not shooting. 158 00:08:45,640 --> 00:08:45,940 Right? 159 00:08:45,940 --> 00:08:47,200 So we fix that problem. 160 00:08:47,200 --> 00:08:51,970 Before we had that problem, you could you could still shoot while you are dying if you're holding the 161 00:08:51,970 --> 00:08:53,350 weapon in your hand.